package com.bytedance.frameworks.baselib.network.http.cronet.a;

import com.bytedance.common.utility.Logger;
import com.bytedance.retrofit2.mime.TypedInput;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.util.zip.GZIPInputStream;

final class SsCronetHttpResponse implements TypedInput {
    private final HttpURLConnection httpURLConnection;
    private final boolean gzip;

    SsCronetHttpResponse(HttpURLConnection connection, boolean gzip) {
        this.httpURLConnection = connection;
        this.gzip = gzip;
    }

    public final String mimeType() {
        return SsCronetHttpClient.getHeaderField(this.httpURLConnection, "Content-Type");
    }

    public final InputStream in() throws IOException {
        InputStream inputStream = this.httpURLConnection.getInputStream();
        if (this.gzip) {
            inputStream = new GZIPInputStream(inputStream);
            if (Logger.debug()) {
                Logger.v("SsCronetHttpClient", "get gzip response for file download");
            }
            return inputStream;
        } else {
            return inputStream;
        }
    }

    public final long length() throws IOException {
        return (long) this.httpURLConnection.getContentLength();
    }
}

